package com.hwadee.controller;


import com.hwadee.pojo.Device;
import com.hwadee.service.DeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin(origins = "*")
@RestController
@RequestMapping("/api/device")
public class DeviceController {

    @Autowired
    private DeviceService deviceService;

    //查询设备列表接口，可根据用户名和设备编号进行筛选
    @GetMapping("/list")
    public List<Device> searchDevice(
            @RequestParam(required = false) String username,
            @RequestParam(required = false) String sn
    ) {
        return deviceService.searchDevice(username, sn);
    }
    //新增设备接口
    @PostMapping("/add")
    public void insert(@RequestBody Device device) {
        deviceService.insert(device);
    }
    //修改设备信息接口
    @PutMapping("/update")
    public void update(@RequestBody Device device) {
        deviceService.update(device);
    }
    //删除设备接口，根据设备 ID 进行删除
    @DeleteMapping("/delete/{id}")
    public void delete(@PathVariable Integer id) {
        deviceService.deleteById(id);
    }

}

